package com.ustarlink.live.channel;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by cfm on 16-1-15.
 */
public class ChannelOpenHelper extends SQLiteOpenHelper {

    private static final String TEXT_TYPE = " TEXT";
    private static final String COMMA_SEP = ",";
    private static final String SQL_CREATE_CHANNEL = "CREATE TABLE " +
            ChannelsTable.ChannelsEntry.TABLE_NAME + " (" +
            ChannelsTable.ChannelsEntry._ID + " INTEGER PRIMARY KEY, " +
            ChannelsTable.ChannelsEntry.COLUMN_NAME_ENTRY_ID + TEXT_TYPE + COMMA_SEP +
            ChannelsTable.ChannelsEntry.COLUMN_NAME_TITLE + TEXT_TYPE + COMMA_SEP +
            ChannelsTable.ChannelsEntry.COLUMN_URL + TEXT_TYPE + COMMA_SEP+
            ChannelsTable.ChannelsEntry.COLUMN_NAME_CATEGORY + TEXT_TYPE +" )";


    private static final String SQL_DELETE_ENTRIES =
            "DROP TABLE IF EXISTS" + ChannelsTable.ChannelsEntry.TABLE_NAME;

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "live_channel.db";

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_CHANNEL);
    }

    public ChannelOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }



    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        super.onDowngrade(db, oldVersion, newVersion);
    }
}
